package com.ruoyi.manage.service.impl;

import java.text.ParseException;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.manage.mapper.OrderDetailMapper;
import com.ruoyi.manage.domain.OrderDetail;
import com.ruoyi.manage.service.IOrderDetailService;

/**
 * 个人订单Service业务层处理
 * 
 * @author rjgc-17
 * @date 2024-12-26
 */
@Service
public class OrderDetailServiceImpl implements IOrderDetailService 
{
    @Autowired
    private OrderDetailMapper orderDetailMapper;

    /**
     * 查询个人订单
     * 
     * @param id 个人订单主键
     * @return 个人订单
     */
    @Override
    public OrderDetail selectOrderDetailById(Long id)
    {
        return orderDetailMapper.selectOrderDetailById(id);
    }

    /**
     * 查询个人订单列表
     * 
     * @param orderDetail 个人订单
     * @return 个人订单
     */
    @Override
    public List<OrderDetail> selectOrderDetailList(OrderDetail orderDetail)
    {
        List<OrderDetail> detailList = orderDetailMapper.selectOrderDetailList(orderDetail);

        detailList.removeIf(detail -> !detail.getCreateBy().equals(SecurityUtils.getUsername()));

        return detailList;
    }

    /**
     * 新增个人订单
     * 
     * @param orderDetail 个人订单
     * @return 结果
     */
    @Override
    public int insertOrderDetail(OrderDetail orderDetail)
    {
        orderDetail.setCreateTime(DateUtils.getNowDate());
        return orderDetailMapper.insertOrderDetail(orderDetail);
    }

    /**
     * 修改个人订单
     * 
     * @param orderDetail 个人订单
     * @return 结果
     */
    @Override
    public int updateOrderDetail(OrderDetail orderDetail)
    {
        orderDetail.setUpdateTime(DateUtils.getNowDate());
        return orderDetailMapper.updateOrderDetail(orderDetail);
    }

    /**
     * 批量删除个人订单
     * 
     * @param ids 需要删除的个人订单主键
     * @return 结果
     */
    @Override
    public int deleteOrderDetailByIds(Long[] ids)
    {
        return orderDetailMapper.deleteOrderDetailByIds(ids);
    }

    /**
     * 删除个人订单信息
     * 
     * @param id 个人订单主键
     * @return 结果
     */
    @Override
    public int deleteOrderDetailById(Long id)
    {
        return orderDetailMapper.deleteOrderDetailById(id);
    }
}
